package com.jhws.business.local.api;

import com.jhws.business.comm.bo.TblBuildingDimBo;
import com.jhws.business.comm.service.ITblBuildingDimService;
import com.jhws.common.base.bo.JsonRespData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/localSynch/comm")
public class CommSynchApi {
    @Resource
    private ITblBuildingDimService buildingDimService;

    /*
     * @author Alex Tan
	 * @date   2017年1月9日
	 * @commnet  同步局域网服务器小区的楼栋信息
	 */
    @RequestMapping("synchBuildings")
    @ResponseBody
    public JsonRespData updateBuildings(String commCode, String timeStamp) throws Exception {
        long lTimeStamp = Long.valueOf(timeStamp);
        HashMap<String, Object> map = new HashMap<>();
        List<TblBuildingDimBo> list = buildingDimService.findTblBuildingDimByWhere("where 1=1 and commCode = '" + commCode + "' and timeStamp > " + lTimeStamp + "");
        lTimeStamp = -1;
        for (TblBuildingDimBo bo : list) {
            lTimeStamp = bo.getTimeStamp() > lTimeStamp ? bo.getTimeStamp() : lTimeStamp;
        }
        map.put("list", list);
        map.put("timeStamp", lTimeStamp);
        return new JsonRespData("updateBuildings", 1, map);
    }
}
